package com.wcfsy.wechat.wx.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.wcfsy.wechat.wx.entity.ActivityInfo;
import com.wcfsy.wechat.wx.pagination.IPage;
import com.wcfsy.wechat.wx.pagination.impl.Page;
import com.wcfsy.wechat.wx.service.IActivityInfoService;
import com.wcfsy.wechat.wx.sys.dao.ActivityInfoDao;

@Service
public class ActivityInfoServiceImpl implements IActivityInfoService {
	private static Logger logger = LoggerFactory
			.getLogger(ActivityInfoServiceImpl.class);

	@Resource
	private ActivityInfoDao activityInfoDao;

	@Override
	public IPage<ActivityInfo> queryActivityByPage(
			Map<String, Object> paramMap, int pageIndex, int pageSize) {
		paramMap.put("index", pageIndex);
		paramMap.put("size", pageSize);
		paramMap.put("limit", "limit");
		IPage<ActivityInfo> page = new Page<ActivityInfo>(
				activityInfoDao.findByParam(paramMap),
				activityInfoDao.count(paramMap), pageIndex, pageSize);
		logger.info("查询活动列表:" + page.getTotal());
		return page;
	}

	@Override
	public void addActivity(ActivityInfo activity) {
		try {
			activityInfoDao.add(activity);
		} catch (Exception e) {
			logger.info("addActivity", e);
		}
	}

	@Override
	public ActivityInfo getActivityById(int activityId) {
		return activityInfoDao.getById(activityId);
	}

	@Override
	public int updateActivity(ActivityInfo activity) {
		try {
			return activityInfoDao.update(activity);
		} catch (Exception e) {
			logger.info("addActivity", e);
			return 0;
		}
	}

	@Override
	public ActivityInfo getActivityByCode(String code) {
		return activityInfoDao.getActivityByCode(code);
	}

	@Override
	public void deleteById(int id) throws Exception {
		activityInfoDao.deleteById(id);
	}

}
